package com.ruoyi.car.controller.carmanage;

import com.car.pojo.TbCarType;
import com.ruoyi.car.service.carmanage.TbCarTypeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/car/type")
public class TbCarTypeController extends BaseController {


    private String prefix="carmanage/type";

    @Autowired
    private TbCarTypeService tbCarTypeService;

    @RequiresPermissions("car:type:view")
    @GetMapping()
    public String carType(){
        return prefix+"/carType";
    }

    @RequiresPermissions("car:type")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbCarType tbCarType){
        startPage();
        List<TbCarType> all = tbCarTypeService.findAll(tbCarType);
        return getDataTable(all);
    }

    /**
     * 导出列表
     */
    @RequiresPermissions("car:type:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbCarType tbCarType)
    {
        List<TbCarType> list = tbCarTypeService.findAll(tbCarType);
        ExcelUtil<TbCarType> util = new ExcelUtil<TbCarType>(TbCarType.class);
        return util.exportExcel(list, "type");
    }

    /**
     * 新增
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存
     */
    @RequiresPermissions("car:type:add")
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbCarType tbCarType)
    {
        return toAjax(tbCarTypeService.insertTbCarType(tbCarType));
    }

    /**
     * 修改
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TbCarType tbCarType = tbCarTypeService.selectTbCarTypeById(id);
        mmap.put("tbCarType", tbCarType);
        return prefix + "/edit";
    }

    /**
     * 修改保存
     */
    @RequiresPermissions("car:type:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbCarType tbCarType)
    {
        return toAjax(tbCarTypeService.updateTbCarType(tbCarType));
    }

    /**
     * 删除
     */
    @RequiresPermissions("car:type:remove")
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbCarTypeService.deleteTbCarTypeByIds(ids));
    }
}
